package cn.ustb.dao;

import cn.ustb.entity.LevelExamList;
import cn.ustb.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface LevelExamListDao {

    @Select({"<script>",
            "select * from levelExamlist",
            "<if test = \"studentId!=null\">"+
                    " where studentId = #{studentId}"+
                    " </if>",
            "</script>"
    })
    List<LevelExamList> getAll(String studentId);

    @Select("select * from levelExamlist where studentId = #{studentId}")
    LevelExamList getByStudentId(String studentId);

    @Select("select * from levelExamlist where studentId = #{studentId} and courseId = #{courseId}")
    LevelExamList getByStudentIdandCourseId(LevelExamList levelExamList);

    @Insert("insert into levelExamlist values(#{studentId},#{courseId},0)")
    void insert(LevelExamList levelExamList);

    @Update("update levelExamlist set CourseId = #{courseId} where studentId = #{studentId}")
    void update(LevelExamList levelExamList);

    @Delete("delete from levelExamlist where studentId = #{studentId}")
    void delete(String studentId);

    @Select("select * from levelExamlist where studentId = #{username}")
    List<LevelExamList> getByUser(User user);

    @Select("select pay from levelexamlist where CourseId = #{courseId} and studentId = #{studentId}")
    int isPay(LevelExamList levelExamList);

    @Update("update levelexamlist set pay=#{i} where CourseId = #{courseId}")
    void updatePayStatus(@Param("i") int i, @Param("courseId") String courseId);
}
